package com.yanfan.alarm.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.alarm.domain.NjAlarmDeviceInfo;
import com.yanfan.alarm.service.INjAlarmDeviceInfoService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 报警主机状态Controller
 *
 * @author genluo
 * @date 2024-10-31
 */
@Api(tags = "报警主机状态")
@RestController
@RequestMapping("/alarm/alarmInfo")
public class NjAlarmDeviceInfoController extends BaseController {
    @Autowired
    private INjAlarmDeviceInfoService njAlarmDeviceInfoService;

    /**
     * 查询报警主机状态列表
     */
    @ApiOperation("报警主机状态分页列表")
    @PreAuthorize("@ss.hasPermi('alarm:alarmInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjAlarmDeviceInfo njAlarmDeviceInfo) {
        startPage();
        List<NjAlarmDeviceInfo> list = njAlarmDeviceInfoService.queryPageList(njAlarmDeviceInfo);
        return getDataTable(list);
    }

    /**
     * 导出报警主机状态列表
     */
    @ApiOperation("导出报警主机状态列表")
    @PreAuthorize("@ss.hasPermi('alarm:alarmInfo:export')")
    @Log(title = "报警主机状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjAlarmDeviceInfo njAlarmDeviceInfo) {
        List<NjAlarmDeviceInfo> list = njAlarmDeviceInfoService.queryPageList(njAlarmDeviceInfo);
        ExcelUtil<NjAlarmDeviceInfo> util = new ExcelUtil<NjAlarmDeviceInfo>(NjAlarmDeviceInfo.class);
        util.exportExcel(response, list, "报警主机状态数据");
    }

    /**
     * 获取报警主机状态详细信息
     */
    @ApiOperation("获取报警主机状态详细信息")
    @PreAuthorize("@ss.hasPermi('alarm:alarmInfo:query')")
    @GetMapping(value = "/{deviceCode}")
    public AjaxResult getInfo(@PathVariable("deviceCode") String deviceCode) {
        return success(njAlarmDeviceInfoService.getById(deviceCode));
    }

    /**
     * 新增报警主机状态
     */
    @ApiOperation("新增报警主机状态")
    @PreAuthorize("@ss.hasPermi('alarm:alarmInfo:add')")
    @Log(title = "报警主机状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody NjAlarmDeviceInfo njAlarmDeviceInfo) {
        return toAjax(njAlarmDeviceInfoService.save(njAlarmDeviceInfo));
    }

    /**
     * 修改报警主机状态
     */
    @ApiOperation("修改报警主机状态")
    @PreAuthorize("@ss.hasPermi('alarm:alarmInfo:edit')")
    @Log(title = "报警主机状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody NjAlarmDeviceInfo njAlarmDeviceInfo) {
        return toAjax(njAlarmDeviceInfoService.updateById(njAlarmDeviceInfo));
    }

    /**
     * 删除报警主机状态
     */
    @ApiOperation("删除报警主机状态")
    @PreAuthorize("@ss.hasPermi('alarm:alarmInfo:remove')")
    @Log(title = "报警主机状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deviceCodes}")
    public AjaxResult remove(@PathVariable String[] deviceCodes) {
        return toAjax(njAlarmDeviceInfoService.removeBatchByIds(Arrays.asList(deviceCodes)));
    }
}
